from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time

browser = webdriver.Firefox()
browser.get('https://www.12306.cn/index/')
id_word_from= "fromStationText"
id_word_to="toStationText"
#
locator_from = (By.ID, id_word_from)
#
locator_to = (By.ID,id_word_to)
wait = WebDriverWait(browser, 10).until(EC.presence_of_all_elements_located(locator_from))
#清空输入框
input = browser.find_element_by_id(id_word_from)
input.clear()
input.send_keys("厦门北")
wait = WebDriverWait(browser, 10).until(EC.presence_of_all_elements_located(locator_to))
#清空输入框
input = browser.find_element_by_id(id_word_to)
input.clear()
input.send_keys("深圳北")
time.sleep(1)
browser.find_element_by_id('citem_0').click()

date_id_word="train_date"
date_locator = (By.ID,date_id_word)
wait = WebDriverWait(browser, 10).until(EC.presence_of_all_elements_located(date_locator))
input = browser.find_element_by_id(date_id_word)
input.clear()
input.send_keys("2023-05-01")
time.sleep(1)

btn = browser.find_element_by_xpath('//*[@id="search_one"]')
btn.click

time.sleep(10)
browser.close()